package avicit.bdp.dcs.json.rest;

import avicit.bdp.common.utils.enums.JobType;
import avicit.bdp.dcs.json.service.DataxJsonService;
import avicit.bdp.dcs.json.service.TaskJsonService;
import avicit.bdp.dcs.task.dto.TaskDTO;
import avicit.platform6.core.rest.msg.ResponseMsg;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @金航数码科技有限责任公司
 * @作者：developer
 * @邮箱：developer@avic-digital.com
 * @创建时间： 2020-08-04 14:31
 * @类说明：生成DataxJson接口
 * @修改记录：
 */
@RestController
@RequestMapping("/api/bdp/dcs/json/DataxJsonRest")
@Api(tags = "生成DataxJson接口")
public class DataxJsonRest {

    @Autowired
    private DataxJsonService dataxJsonService;
    @Autowired
    private TaskJsonService taskJsonService;

    @GetMapping("/buildDataxJson")
    @ApiOperation(value = "构建DataxJson")
    public ResponseMsg<String> buildDataxJson(@ApiParam(value = "任务id", name = "taskId") @RequestParam String taskId) throws Exception{
        ResponseMsg<String> responseMsg = new ResponseMsg<>();
        TaskDTO task = new TaskDTO();
        task.setId(taskId);
        task.setJobType(JobType.SYNC.getCode());
        responseMsg.setResponseBody(dataxJsonService.buildDataxJson(task));
        return responseMsg;
    }

    @PostMapping("/saveProcessDefinition")
    @ApiOperation(value = "保存DS流程定义")
    public ResponseMsg<Integer> saveProcessDefinition(@ApiParam(value = "jobId", name = "jobId") @RequestParam String jobId) throws Exception{
        ResponseMsg<Integer> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(taskJsonService.saveProcessDefinition(jobId));
        return responseMsg;
    }

    @GetMapping("/getDataxPluginParam")
    @ApiOperation(value = "获取插件参数")
    public ResponseMsg<Map<String, String>> getDataxPluginParam(@ApiParam(value = "数据源id", name = "datasourceId", required = true)
                                                                @RequestParam String datasourceId) throws Exception{
        ResponseMsg<Map<String, String>> responseMsg = new ResponseMsg<>();
        responseMsg.setResponseBody(dataxJsonService.getDataxPluginParam(datasourceId));
        return responseMsg;
    }

}
